﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>-.-</title>
<link href="./styles/global.css" rel="stylesheet" type="text/css" media="all" />
<!-- <script type="text/javascript" charset="utf-8" src="../plugins/kindeditor/kindeditor.js"></script>
<script type="text/javascript" charset="utf-8" src="../plugins/kindeditor/lang/zh_CN.js"></script> -->
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/bootstrap.min.js"></script>
<script type="text/javascript" src="scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="scripts/bootstrapValidator.js"></script>
<link href="styles/bootstrap.min.css" rel="stylesheet" />
<link href="styles/bootstrapValidator.css" rel="stylesheet" />
<script type="text/javascript" src="scripts/fileinput.min.js"></script>
<link href="styles/fileinput.min.css" rel="stylesheet"/>
<script type="text/javascript" src="scripts/fileinput_local_zh.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('#addProductForm').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            "furnitureInfo.furnitureName": {
                message: 'The username is not valid',
                validators: {
                    notEmpty: {
                        message: '商品名称不能为空'
                    },
                    stringLength: {
                        min: 6,
                        max: 255,
                        message: '商品名称要大于6位'
                    },
                }
            },
            "furnitureInfo.furnitureId": {
                message: 'The furnitureInfo.furnitureId is not valid',
                validators: {
                    notEmpty: {
                        message: '商品ID不能为空'
                    },
                    stringLength: {
                        min: 6,
                        max: 30,
                        message: '商品ID要大于6位小于30位'
                    },
                    regexp: {
                        regexp: /^[A-Za-z0-9]+$/,
                        message: '商品ID只能是数字和字母'
                    }
                }
            },
            "furnitureInfo.basePrice": {
                message: 'The furnitureInfo.furnitureId is not valid',
                validators: {
                    notEmpty: {
                        message: '采购价格不能为空'
                    },
                    stringLength: {
                        min: 1,
                        max: 10,
                        message: '采购价格不能超过10位'
                    },
                    regexp: {
                        regexp: /^[0-9.]+$/,
                        message: '采购价格格式错误'
                    } 
                }
            },
            
            "furnitureInfo.salePrice": {
                message: 'The furnitureInfo.salePrice is not valid',
                validators: {
                    notEmpty: {
                        message: '销售价格不能为空'
                    },
                    stringLength: {
                        min: 1,
                        max: 10,
                        message: '销售价格不能超过10位'
                    },
                     regexp: {
                        regexp: /^[0-9.]+$/,
                        message: '销售价格格式错误'
                    }
                }
            },
            "furnitureInfo.amount": {
                message: 'The furnitureInfo.amount is not valid',
                validators: {
                    notEmpty: {
                        message: '库存量不能为空'
                    },
                    stringLength: {
                        min: 1,
                        max: 10,
                        message: '库存量不能超过10位'
                    },
                    regexp: {
                        regexp: /^[0-9]+$/,
                        message: '库存量格式错误'
                    }
                }
            },
            
            "furnitureInfo.description": {
                validators: {
                    notEmpty: {
                        message: '描述不能为空'
                    }
                }
            },

        }
    });
});
</script>
</head>
<body>
					<s:action name="furnitureTypeAction!showFurnitureType" executeResult="false"></s:action>
			<ul id="myTab" class="nav nav-tabs">
						<li class="active"><a href="#info" data-toggle="tab"> 商品添加 </a></li>
					</ul> 

                    <form id="addProductForm" action="FurnitureInfo_addFurnitureInfo.action" enctype="multipart/form-data" method="post" class="form-horizontal">
                        <div id="myTabContent" class="tab-content" style="margin: 20px">
						<div class="tab-pane fade in active" id="info">

                        <fieldset>

                            <div class="form-group">
                                <label class="col-lg-3 control-label">商品名称</label>
                                <div class="col-lg-5">
                                    <input type="text" name="furnitureInfo.furnitureName" class="form-control"  id="furnitureInfoname" placeholder="请输入商品名称"/>
                              </div>
                            </div>
                            
                             <div class="form-group">
									<label class="col-lg-3 control-label">商品货号:</label> 
									<div class="col-lg-5">
										<input type="text" class="form-control" name="furnitureInfo.furnitureId" id="furnitureId" placeholder="请输入商品货号" onblur="checkFurnitureId()">
									</div>
									<span id="span1"></span>
							</div>


                           <div class="form-group">
                                <label class="col-lg-3 control-label">商品分类</label>
                                <div class="col-lg-5">
                                    <select class="form-control" name="category.id">
                                    	<option value="">-- 选择分类 --</option>
                                    	<s:iterator value="#session.typeToShow"  id="ty">
                                        	<option value='<s:property value="#ty.id"/>'/><s:property value="#ty.type"/></option>
                                        </s:iterator>
                                    </select>
                                </div>
                            </div> 
                            
                            <div class="form-group">
									<label class="col-lg-3 control-label">采购价格:</label> 
									<div class="col-lg-5">
										<input type="text" class="form-control" name="furnitureInfo.basePrice"  id="name" placeholder="请输入采购价格">
								</div>
							</div>
							
							<div class="form-group">
									<label class="col-lg-3 control-label">销售价格:</label> 
									<div class="col-lg-5">
										<input type="text" class="form-control" name="furnitureInfo.salePrice" id="name" placeholder="请输入销售价格">
									</div>
							</div>
							<div class="form-group">
									<label class="col-lg-3 control-label">库存量:</label> 
									<div class="col-lg-5">
										<input type="text" class="form-control" name="furnitureInfo.amount" id="name" placeholder="请输入库存量">
									</div>
							</div>
							
							<div class="form-group">
									<label class="col-lg-3 control-label">商品描述:</label> 
									<div class="col-lg-5">
										 <textarea class="form-control" rows="3" name="furnitureInfo.description" id="name" placeholder="商品描述" ></textarea>
									
									</div>
							</div>
							<div class="form-group">
									<label class="col-lg-3 control-label">上传图片:</label> 
									<div class="col-lg-5">
										<input id="fileupload" name="image" type="file" multiple />
									</div>
							</div>
							

                        <div class="form-group">
                            <div class="col-lg-9 col-lg-offset-3">
                                <button type="submit" class="btn btn-primary">Submit</button>
                            </div>
                        </div>
						</div>				
						</div>
                 </form>

<script type="text/javascript">
	$(function(){
		$("#fileupload").fileinput({
			language: 'zh',
			allowedFileExtensions : ['jpg', 'png','gif'],
			maxFilesNum: 10,
		});
	});

</script>
	
<script type="text/javascript">
function checkFurnitureId(){  
    var furnitureId = document.getElementById("furnitureId").value;  
    //传统的ajax校验  
    //1.创建异步交互对象，  
    var xhr = createXmlHttp();  
    //2设置监听  
    xhr.onreadystatechange = function(){  
        if(xhr.readyState == 4){  
            if(xhr.status == 200){  
                document.getElementById("span1").innerHTML = xhr.responseText;  
            }  
        }  
    }  
      
    //3打开连接  
    xhr.open("GET","${pageContext.request.contextPath}/FurnitureInfo_findByFurnitureId.action?furnitureInfo.furnitureId="+furnitureId,true);  
    //4发送  
    xhr.send(null);       
    }     
          
    //创建XmlHttp对象  
    function createXmlHttp(){  
        var xmlHttp;  
        try{  
            xmlHttp= new XMLHttpRequest();  
        }catch(e){  
            try{  
                xmlHttp=new ActiveXObject("Msxm12.XMLHTTP");  
            }catch(e){  
                try{  
                    xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");  
                }catch(e){}  
            }             
        }  
          
         return xmlHttp;      
    }  
</script>
</body>
</html>
